///mine.txt - An object that explodes whenever anyone gets close to it.
//Cell 0 - The number of damage (d8) this mine does. If 0, defaults to 6.
//Cell 1,2 - A stuff done flag. If > 0, this mine has been deactivated and should start destroyed.
//Cell 3 - DIsarming difficulty

beginobjectscript; // mine

variables;
short disarmed = 0;
short exploded = 0;
short near_char;
short r1;
short cur_tick;

body;

beginstate INIT_STATE;
	if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0)) {
		if (get_sdf(get_memory_cell(1),get_memory_cell(2)) > 0)
			kill_object(ME,0);
		}
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
	if ((disarmed) || (exploded))
		end();
	if (gf(41,3) == 0) 
		end();
	if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0)) {
		if (get_sdf(get_memory_cell(1),get_memory_cell(2)) > 0)
			end();
		}
		
	if (can_detect_pc(2) > 0) {
		create_text_bubble("Tick.");
		print_str_color("You trigger an alarm. If not disarmed soon, it will begin to shriek!",2);
		cur_tick = get_current_tick();
		if (is_combat())
			cur_tick = cur_tick - 1;
		set_state(12);
		

		}
break;

beginstate 12;
	if (disarmed)
		set_state(START_STATE);
	if (exploded)
		set_state(START_STATE);
	if (cur_tick < get_current_tick() - 2) {

		exploded = 1;
		kill_object(ME,0);
		pc_heard_sound(170);
		if (gf(42,11) > 0)
			print_str_color("  The alarm lets out a long, hideous shriek!",2);
			else begin_talk_mode(11);
		}
break;

beginstate USE_STATE;
	if (gf(41,3) == 0) {
		print_str("Examine Alarm: It is inactive. The fort must not be on high alert.");
		end();
		}
	if (exploded) {
		print_str("Disarm Alarm: It's already gone off.");
		}
	else if (disarmed) {
		print_str("Disarm Alarm: You already did.");
		}
	else if (get_stat(21) >= get_memory_cell(3)) {
		print_str("Disarm Alarm: You manage to disarm the alarm!");
		pc_heard_sound(195);
		create_text_bubble("Click.");
		disarmed = 1;

		kill_object(ME,0);
		award_party_xp(BASE_TRAP_XP - 5,trap_lev_to_xp_lev(get_memory_cell(3)));
		}
		else {
			print_big_str("Disarm Alarm: Your Mechanics skill isn't high enough. (Difficulty: ",get_memory_cell(3),").");
			}
break;